package com.yidu.t299.dao.fxj;

import com.yidu.t299.domain.fxj.ClassP;
import com.yidu.t299.domain.fxj.ClassS;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClasscMapper {

    /**
     * 添加
     * @return 影响的行数(返回1则为成功)
     */
    @Insert("insert into class(class_id,class_name,class_type,startClass_time,startClass_num,school_id,record_id,classroom_id,lesson_id)" +
            " values (" +
            "#{classId,jdbcType=INTEGER}," +
            "#{className,jdbcType=VARCHAR}," +
            "#{classType,jdbcType=VARCHAR}," +
            "#{startClassTime,jdbcType=DATE}," +
            "#{startClassNum,jdbcType=INTEGER}," +
            "#{schoolId,jdbcType=INTEGER}," +
            "#{recordId,jdbcType=INTEGER}," +
            "#{classroomId,jdbcType=INTEGER}," +
            "#{lessonId,jdbcType=INTEGER})")
    int insert(ClassS classS);


    /**
     * 删,根据班级号删
     * @return 影响的行数(返回1则为成功)
     * @param classroom_id
     */
    @Delete("delete from class where classroom_id = #{classroom_id,jdbcType=INTEGER}")
    int deleteByPrimaryKey(Integer classroom_id);


    /**
     * 根据信息修改其数据
     * @return 影响的行数(返回1则为成功)
     */
    @Update({"update class set" +
            " class_name = #{className,jdbcType=VARCHAR}," +
            " class_type = #{classType,jdbcType=VARCHAR}," +
            " startClass_time = #{startClassTime,jdbcType=VARCHAR}," +
            " startClass_num = #{startClassNum,jdbcType=INTEGER}," +
            " school_id = #{schoolId,jdbcType=INTEGER}," +
            " record_id = #{recordId,jdbcType=INTEGER}," +
            " classroom_id = #{classroomId,jdbcType=INTEGER}," +
            " lesson_id = #{lessonId,jdbcType=INTEGER}  " +
            "where class_id = #{classId,jdbcType=INTEGER}"})
    int updateByPrimaryKey(ClassS classS);

    /**
     * 行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from (select class_id,class_name,class_type,startClass_time,startClass_num,record_name,school_name from class  " +
            "            join lesson on class.lesson_id = lesson.lesson_id  " +
            "            join record on record.record_id = class.record_id " +
            "            join school on school.school_id = record.school_id) p where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);


    /**
     * 分页
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 校区对象集合
     */
    @Select("select * from (select class_id,class_name,class_type,startClass_time,startClass_num,record_name,school_name from class  " +
            "join lesson on class.lesson_id = lesson.lesson_id  " +
            "join record on record.record_id = class.record_id " +
            "join school on school.school_id = record.school_id) p  " +
            "where 1=1 ${condition} limit #{page},#{rows} ")
    @ResultMap("classP")
    List<ClassP> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);


    /**
     * 根据编号查询指定的信息
     * @return 校区对象
     */
    @Select("select * from ( select * from (select class_id,class_name,class_type,startClass_time,startClass_num,record_name,school_name from class  " +
            "join lesson on class.lesson_id = lesson.lesson_id  " +
            "join record on record.record_id = class.record_id " +
            "join school on school.school_id = record.school_id) p  " +
            "where 1=1 ${condition} limit #{page},#{rows}) p " +
            "where class_id = #{classId,jdbcType=INTEGER}")
    @Results(id = "classP" ,value = {
            @Result(id = true,column = "class_id",property = "classId"),
            @Result(column = "class_name",property = "className"),
            @Result(column = "class_type",property = "classType"),
            @Result(column = "startClass_time",property = "startClassTime"),
            @Result(column = "startClass_num",property = "startClassNum"),
            @Result(column = "record_name",property = "recordName"),
            @Result(column = "school_name",property = "schoolName")
    })
    ClassP selectByPrimaryKey(Integer classId);

    /*
        根据class表id查所有
     */
    @Select("select * from class where class_id = #{classId,jdbcType=INTEGER} ")
    @Results(id = "classS" ,value = {
            @Result(id = true,column = "class_id",property = "classId"),
            @Result(column = "class_name",property = "className"),
            @Result(column = "class_type",property = "classType"),
            @Result(column = "startClass_time",property = "startClassTime"),
            @Result(column = "startClass_num",property = "startClassNum"),
            @Result(column = "school_id",property = "schoolId"),
            @Result(column = "record_id",property = "recordId"),
            @Result(column = "classroom_id",property = "classroomId"),
            @Result(column = "lesson_id",property = "lessonId"),
    })
    ClassS selectId(Integer classId);

}
